#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <error.h>

int main()
{
    int i;
    if ((i = write(1, "Here is some data\n", 19)) < 0) {
        printf("i=%d\n", i);
       int a;
       char *s = "a write error has occurred on file descriptor 1\n";
       a = write(2, s, 50);
       printf("a=%d\n", a);
    }
    printf("i=%d\n", i);

    char buffer[128];
    int nread;
    nread = read(0, buffer, 128);
    printf("read %d chars\n", nread - 1);
    printf("write %d chars\n", write(1, "", 0));
    int openfile;
    char *filename = "/tmp/new";
    openfile = open(filename, O_RDWR|O_CREAT|O_APPEND);
    if (openfile > 0) {
        printf("open=%d\n", openfile);
        write(openfile, "hello world", 20);
        close(openfile);
    } else {
        printf("open=%d\n", openfile);
        printf("%d\n", error);
    }
    exit(0);
}
